package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.service.IEmployeeService;
import cn.wolfcode.rbac.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private IEmployeeService employeeService;
    @ResponseBody
    @RequestMapping("/login")
    public Object login(String username,String password){
        JSONResult json = new JSONResult();
        try {
            employeeService.login(username,password);
        } catch (Exception e) {
            json.mark(e.getMessage());
        }
        return  json;
    }
    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:/login.html";
    }
}
